package com.ruoyi.district.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.district.domain.MfDistrict;
import com.ruoyi.district.service.IMfDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区信息Controller
 * 
 * @author yuanrui
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/district")
public class MfDistrictController extends BaseController
{
    @Autowired
    private IMfDistrictService mfDistrictService;

    /**
     * 查询地区信息列表
     */
    @RequiresPermissions("district:district:list")
    @GetMapping("/list")
    public AjaxResult list(MfDistrict mfDistrict)
    {
        List<MfDistrict> list = mfDistrictService.selectMfDistrictList(mfDistrict);
        return success(list);
    }

    /**
     * 导出地区信息列表
     */
    @RequiresPermissions("district:district:export")
    @Log(title = "地区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MfDistrict mfDistrict)
    {
        List<MfDistrict> list = mfDistrictService.selectMfDistrictList(mfDistrict);
        ExcelUtil<MfDistrict> util = new ExcelUtil<MfDistrict>(MfDistrict.class);
        util.exportExcel(response, list, "地区信息数据");
    }

    /**
     * 获取地区信息详细信息
     */
    @RequiresPermissions("district:district:query")
    @GetMapping(value = "/{districtId}")
    public AjaxResult getInfo(@PathVariable("districtId") String districtId)
    {
        return success(mfDistrictService.selectMfDistrictByDistrictId(districtId));
    }

    /**
     * 新增地区信息
     */
    @RequiresPermissions("district:district:add")
    @Log(title = "地区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MfDistrict mfDistrict)
    {
        return toAjax(mfDistrictService.insertMfDistrict(mfDistrict));
    }

    /**
     * 修改地区信息
     */
    @RequiresPermissions("district:district:edit")
    @Log(title = "地区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MfDistrict mfDistrict)
    {
        return toAjax(mfDistrictService.updateMfDistrict(mfDistrict));
    }

    /**
     * 删除地区信息
     */
    @RequiresPermissions("district:district:remove")
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{districtIds}")
    public AjaxResult remove(@PathVariable String[] districtIds)
    {
        return toAjax(mfDistrictService.deleteMfDistrictByDistrictIds(districtIds));
    }
}
